package com.shuqing.dao;

import com.github.pagehelper.Page;
import com.shuqing.domain.Record;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface RecordMapper {
    Integer addRecord(Record record);

    /**
     * 查询借阅记录
     *
     * @param record
     * @return
     */
    @Select({"<script>" +
            "select * from record " +
            "where 1=1 " +
            "<if test=\"bookname != null\"> AND bookname like CONCAT('%', #{bookname},'%') </if>" +
            "<if test=\"borrower != null\"> AND borrower like CONCAT('%', #{borrower},'%') </if>" +
            "order by record_remandtime desc" +
            "</script>"
    })
    @Results(id = "recordMap", value = {
            //id 字段默认为false，表示不是主键
            //column 对应数据库字段名，property 对应实体类属性名称
            @Result(id = true, column = "record_id", property = "id"),
            @Result(column = "record_bookname", property = "bookname"),
            @Result(column = "record_bookisbn", property = "bookisbn"),
            @Result(column = "record_borrower", property = "borrower"),
            @Result(column = "record_borrowtime", property = "borrowTime"),
            @Result(column = "record_remandtime", property = "remandTime")
    })
    Page<Record> searchRecords(Record record);

}

